﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Reflection;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace Components
{
    public class WorkflowEngine
    {
        private static Dictionary<string, Type> componentTypes;
        private static Dictionary<Type, Type> componentEditors;

        //static void Init()
        //{
        //    componentTypes=new Dictionary<string, Type>();
        //    componentEditors = new Dictionary<Type, ComponentEditorBase>();

        //    Assembly assembly = typeof(WorkflowEngine).Assembly;
        //    Type[] types = assembly.GetTypes();
        //    foreach (Type type in types)
        //    {
        //        if (type.IsSubclassOf(typeof(WorkflowComponentBase)))
        //            ComponentTypes.Add(type.Name, type);
        //        if (type.IsSubclassOf(typeof(ComponentEditorBase)))
        //        {
        //            ComponentEditorBase editor = (ComponentEditorBase)Activator.CreateInstance(type);
        //            if (!ComponentEditors.ContainsKey(editor.ComponentType))
        //                ComponentEditors.Add(editor.ComponentType, editor);
        //        }
        //    }
        //}

        public static Dictionary<string, Type> ComponentTypes
        {
            get
            {
                return componentTypes;
            }
        }

        public static Dictionary<Type, Type> ComponentEditors
        {
            get
            {
                return componentEditors;
            }
        }

        public static void RegisterComponent(Type componentType)
        {
            if (componentTypes == null)
                componentTypes = new Dictionary<string, Type>();
            if (!componentTypes.ContainsKey(componentType.Name))
                componentTypes.Add(componentType.Name, componentType);
        }

        public static void RegisterEditor(Type type, Type editorType)
        {
            if (componentEditors==null)
                componentEditors = new Dictionary<Type, Type>();
            if(!componentEditors.ContainsKey(type))
                componentEditors.Add(type, editorType);
        }

    }
}
